# 继承
# 定义父类
class Animal:
    def __init__(self, name):
        self.name = name
    def eat(self):
        print(f'{self.name} eat')
    def drink(self):
        print(f'{self.name} drink')
    def run(self):
        print(f'{self.name} run')
    def sleep(self):
        print(f'{self.name} sleep')

# 定义子类，继承父类
class Dog(Animal):
    def __init__(self, name, age, color):
        # 如果子类有构造方法，不会调用父类的构造方法
        # 需要手动调用父类的构造方法，有参构造要带参数
        Animal.__init__(self, name)
        self.age = age
        self.color = color
    def bark(self):
        print(f'{self.name} bark')
    def say(self):
        print(f'{self.name} say {self.age} {self.color}')

# 测试
if __name__ == '__main__':
    d1 = Dog('dog1', 2, 'blue')
    # 调用父类属性，方法
    print(d1.name)
    d1.eat()
    d1.drink()
    d1.run()
    d1.sleep()
    # 调用子类属性，方法
    print(d1.age)
    print(d1.color)
    d1.bark()
    d1.say()
